import request from '@/utils/request'

export const areaMapping = () => {
  return request({
    url: '/api/map/globalEntitys/0',
    method: 'get',
    loading: true
  })
}

export const globalMapping = () => {
  return request({
    url: '/api/map/globalEntitys/0',
    method: 'get',
    loading: true
  })
}

export function geoJson(areaCode) {
  const countryCode = areaCode.substring(0, 3)
  // 判断是否为区级以下数据，是的话，重新获取最新文件
  const isArea = areaCode.slice(-2)
  if(isArea == '00'){
    return request({
      url: '/geo/full/' + countryCode + '/' + areaCode + '_full.json',
      method: 'get',
      loading: true
    })
  }else{
    return request({
      url: '/geo/full/' + countryCode + '/' + areaCode + '_full.json'+ '?'+(Math.floor(Math.random() * 1000) + 1),
      headers: {
        'Cache-Control': 'no-cache'
      },
      method: 'get',
      loading: true
    })
  }
}

export function saveMap(data) {
  return request({
    url: '/api/map/saveMapNode',
    method: 'post',
    loading: true,
    data
  })
}

export function replaceMap(data) {
  return request({
    url: '/api/map/exchangeMapFile',
    method: 'post',
    loading: true,
    data
  })
}

export function restMapFile(data) {
  return request({
    url: '/api/map/resetMapFile',
    method: 'post',
    headers: { 'content-type': 'application/json' },
    loading: true,
    data
  })
}


export function removeMap(data) {
  return request({
    url: '/api/map/delMapNode',
    method: 'post',
    loading: true,
    data
  })
}
